﻿using System.Data.Objects;
using System.Data.Objects.DataClasses;
namespace hieunv.MVC3.App.Models
{
	public static class Extensions
	{
		public static bool Insert<T>(this ObjectContext ctx, T x, bool save) where T : class
		{
			ctx.CreateObjectSet<T>().AddObject(x);
			if (save)
			{
				return ctx.SaveChanges() > 0;
			}
			return true;
		}
		public static bool Insert<T>(this ObjectContext ctx, T x) where T : class
		{
			return Insert<T>(ctx, x, true);
		}
		public static bool Delete<T>(this ObjectContext ctx, T x, bool save) where T : class
		{
			ctx.CreateObjectSet<T>().DeleteObject(x);
			if (save)
			{
				return ctx.SaveChanges() > 0;
			}
			return true;
		}
		public static bool Delete<T>(this ObjectContext ctx, T x) where T : class
		{
			return Delete<T>(ctx, x, true);
		}
	}
}
